//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                        . ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' |_|/ |
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖保佑             永无BUG 
/**AI 简单 */
class AI_base {
	/**队伍 0-警 1-匪 */
	protected troops: number;
	/**玩家击杀 */
	protected killNumber: number;
	/**青蛙尺寸 */
	protected size: number;
	/**遮罩时间 */
	protected zhetime: number;
	/**名字 */
	protected name: string;
	/**id */
	protected userId: any;
	/**房间号 */
	protected roomId: number;
	protected x: number;
	protected y: number;
	/**青蛙颜色 */
	protected frogType: number;
	/**青蛙等级 */
	protected level: number;
	/**类型 */
	protected type: any;
	/**线长 */
	protected lineLength: number;
	/**速度 */
	protected speed: number;
	/**半径 */
	protected radius: number;
	/**是否是AI */
	protected isAI: boolean;
	/**是否连线 */
	protected ishadLine: boolean;
	/**心跳 */
	protected lastHeartbeat: any;
	/**伙伴 */
	protected partner: any;
	/**吐舌状态0-没吐 1-吐了 */
	protected states: any;
	protected socket;
	/**连线的青蛙id */
	protected otherLineUser;
	/**是否待定 */
	protected isDetermined: boolean;
	/**断线处罚 */
	protected disconnection_line;
	/**断线处罚时间 */
	protected disconnection_line_time;
	/**道具状态 */
	protected propStates;
	/**是否死亡 */
	protected death;
	//判断玩家是否处于新手保护
	protected NewHandProtect;
	/**下一个点的坐标 */
	protected targetdir: egret.Point;
	/**装扮 */
	protected dressup;
	/**思考间隔 */
	protected Think_interval: number;
	/**思考时间 */
	protected Think_time: any;
	/**出错概率 */
	protected Error_probability: number;
	/**是否使用 */
	protected isUsed: boolean;
	/**可视范围 */
	protected Visual_scope: number;
	/**躲避权重 */
	protected Avoid_weight: number;
	/**追击权重 */
	protected Pursuit_weight: number;
	/**防撞墙权重 */
	protected Obstacle_weight: number;
	/**防断线权重 */
	protected Line_weight: number;
	/**线拉开的权重 */
	protected AddLine_weight: number;
	/**吃道具权重 */
	protected prop_weight: number;
	/**吐舌状态 */
	protected shootStates: any;
	/**随机移动权重 */
	protected RandomMove_weight: number;
	/**分数 */
	protected grade: number;
	/**舌宽 */
	protected tongueWide: number;
	/**断线定时器 */
	protected breakLineTimer: egret.Timer;
	/**断线时间 */
	protected breakLineMin: number;
	/**是否检测断线 */
	protected isCheckBreakLine: boolean;
	/**吐舌定时器 */
	protected shootTimer: egret.Timer;
	/**是否可以吐舌 */
	protected isCanShoot: boolean;
	/**变色定时器 */
	protected changeColorTimer: egret.Timer;
	/**仇人ID */
	protected enemyId: any;
	/**重置仇人定时器 */
	protected enemyTimer: egret.Timer;

	protected My_position: egret.Point;
	protected Next_target: egret.Point;
	public constructor(userid) {
		this.size = 50;
		this.states = 0;
		this.killNumber = 0;
		this.troops = -1;
		this.zhetime = 0;
		this.name = randomName.getInstance().getRandomName();
		this.userId = userid;
		this.roomId = -1;
		this.x = 0;
		this.y = 0;
		this.frogType = Math.floor(Math.random() * 2 + 0);
		this.level = 1;
		this.type = "player";
		this.lineLength = AIPropsMgr.getInstance().GetAttributesByGrade(0).frogLineLength;
		this.speed = serverConfig.config.initUserSpeed;
		this.radius = 5;
		this.isAI = true;
		this.ishadLine = false;
		this.otherLineUser = -1;
		this.lastHeartbeat = Date.now();
		this.socket = -1;
		this.grade = 0;
		this.tongueWide = AIPropsMgr.getInstance().GetAttributesByGrade(0).tongueWide;


		this.Error_probability = 20;
		this.Think_interval = 500;
		this.Think_time = 0;
		this.isUsed = false;
		this.Visual_scope = 500;
		//-------------------------------权重
		this.Avoid_weight = 100;
		this.Pursuit_weight = 200;
		this.Line_weight = 300;
		this.AddLine_weight = 200;
		this.RandomMove_weight = 50;
		this.Obstacle_weight = 50;
		this.prop_weight = 200;



		this.disconnection_line = false,
			this.disconnection_line_time = -1,
			this.propStates = [{
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			}, {
				getPropType: -1,
				PropStartTime: -1,
			},
			{
				getPropType: -1,
				PropStartTime: -1,
			},],
			this.death = {
				isDeath: false,
				deadStartTime: 0
			};
		this.NewHandProtect = {
			isProtect: false,
			ProtectStartTime: 0
		};
		this.targetdir = new egret.Point();
		this.dressup = {
			decorateId: -1,
			trailingId: -1
		};
		this.shootStates =
			{
				shootStartTime: 0,
				isShoot: false,
				point: {
					x: 0,
					y: 0
				}
			};
		this.isCheckBreakLine = true;
		this.breakLineMin = 0;
		this.breakLineTimer = new egret.Timer(0, 0);
		this.isCanShoot = true;
		this.shootTimer = new egret.Timer(0, 0);
		this.changeColorTimer = new egret.Timer(6000, 1);
		this.enemyId = null;
		this.enemyTimer = new egret.Timer(4000, 1);

		this.My_position = new egret.Point(0, 0);
		this.Next_target = new egret.Point(0, 0);
	}
	/**检测是否断线
	 * （连线玩家等级小于3级抽签并在3-10秒内断线）
	 */
	protected checkIsBreakLine() {
		if (!this.ishadLine) {
			if (this.breakLineTimer.running) {
				this.breakLineTimer.stop();
				this.breakLineTimer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.breakLine, this);
			}
			this.isCheckBreakLine = true;
			return;
		}
		if (!this.isCheckBreakLine) {
			return;
		}
		if (this.otherLineUser == null) {
			return;
		}
		/**跟自己连线的青蛙 */
		let lineFrog;
		if (this.otherLineUser == DataProl.account) {//连线对象是玩家
			lineFrog = AIUserMgr.getInstance().currentPlayer;
		} else {
			lineFrog = serverAIMgr.getInstance().AIPools[this.otherLineUser];
		}
		if (lineFrog == null) {
			return;
		}
		this.isCheckBreakLine = false;
		if (lineFrog.level <= 3) {
			/**随机抽签 */
			let randomNum = Math.random() * 1;
			if (randomNum > 0.5) {
				/**随机断线时间3-10秒 */
				this.breakLineMin = Math.floor(Math.random() * 7000 + 3000);
				this.breakLineTimer = new egret.Timer(this.breakLineMin, 1);
				this.breakLineTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.breakLine, this);
				this.enemyId = lineFrog.userId;
				this.breakLineTimer.start();
			}
		}
	}
	/**断线 */
	protected breakLine() {
		this.breakLineTimer.stop();
		this.breakLineTimer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.breakLine, this);
		AIServer.getInstance().breakLine(this.userId);
		if (this.shootTimer.running) {
			this.shootTimer.reset();
		}
	}
	/**是否出错*/
	protected isError() {
		let mistakeRate = Math.random() * 100;
		if (mistakeRate <= this.Error_probability)
		{ return true; }
		else {
			return false;
		}
	}


	/**探测可视敌人 */
	protected Detect_enemy() {
		/**除了自己的所有的可视玩家 */
		let Video_player = [];
		/**房间内所有玩家 */
		let All_player = AIServer.getInstance().roomInfo.roomUser;
		/**自己的坐标 */
		this.My_position.setTo(this.x, this.y);
		/**下一个点坐标 */

		for (let i = 0; i < All_player.length; i++) {
			// /**其他玩家坐标 */
			// let Player_position = new egret.Point(All_player[i].x, All_player[i].y);
			// /**自己与其它玩家的距离 */
			// let YouMe_distance = egret.Point.distance(this.My_position, Player_position);
			let YouMe_distance = MathUtils.distance(this.My_position.x, this.My_position.y, All_player[i].x, All_player[i].y);
			//判断进入可视范围；不是自己；不是自己连线的玩家
			if (this.Visual_scope > YouMe_distance && All_player[i].userId != this.userId && this.otherLineUser != All_player[i].userId) {
				Video_player.push(All_player[i]);
				//自己连线
				if (this.ishadLine) {
					//目标连线
					if (All_player[i].ishadLine) {
						/**与自己连线的青蛙 */
						let otherLineUser;
						/**其他青蛙的连线青蛙*/
						let frogLineUser;
						if (this.otherLineUser == DataProl.account) {//连线对象是玩家
							otherLineUser = AIUserMgr.getInstance().currentPlayer;
						}
						else {
							otherLineUser = serverAIMgr.getInstance().AIPools[this.otherLineUser];
						}
						if (All_player[i].otherLineUser == DataProl.account) {//连线对象是玩家
							frogLineUser = AIUserMgr.getInstance().currentPlayer;
						}
						else {
							frogLineUser = serverAIMgr.getInstance().AIPools[All_player[i].otherLineUser];
						}
						let dis_o2m = MathUtils.getFootfallDistance(this.x, this.y, otherLineUser.x, otherLineUser.y, All_player[i].x, All_player[i].y);
						let dis_m2o = MathUtils.getFootfallDistance(All_player[i].x, All_player[i].y, frogLineUser.x, frogLineUser.y, this.x, this.y);
						let pt_o2m = MathUtils.getFootfallPoint(this.x, this.y, otherLineUser.x, otherLineUser.y, All_player[i].x, All_player[i].y);
						let pt_m2o = MathUtils.getFootfallPoint(All_player[i].x, All_player[i].y, frogLineUser.x, frogLineUser.y, this.x, this.y);
						/**pt_o2m在AIPools[i]线段内为true */
						let on_line_o2m = MathUtils.checkPointOnSegment(this.x, this.y, otherLineUser.x, otherLineUser.y, pt_o2m.x, pt_o2m.y);
						/** pt_m2o在frog线段内为true*/
						let on_line_m2o = MathUtils.checkPointOnSegment(All_player[i].x, All_player[i].y, frogLineUser.x, frogLineUser.y, pt_m2o.x, pt_m2o.y);
						if (on_line_o2m == false && on_line_m2o == true) //垂点都在线上，谁短谁逃跑
						{
							if (dis_o2m < dis_m2o)  //追击
							{
								this.Next_target.x = All_player[i].x - (this.x + otherLineUser.x) / 2;
								this.Next_target.y = All_player[i].y - (this.y + otherLineUser.y) / 2;
								this.Next_target.normalize(this.Pursuit_weight * (1 - YouMe_distance / this.Visual_scope));
							}
							else  //逃跑
							{
								this.Next_target.x = -this.x - (All_player[i].x + frogLineUser.x) / 2;
								this.Next_target.y = -this.y - (All_player[i].x + frogLineUser.x) / 2;
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
						}
						else   //都不在垂线上
						{
							if (dis_o2m > dis_m2o)  //追击
							{
								this.Next_target.x = All_player[i].x - (this.x + otherLineUser.x) / 2;
								this.Next_target.y = All_player[i].y - (this.y + otherLineUser.y) / 2;
								this.Next_target.normalize(this.Pursuit_weight * (1 - YouMe_distance / this.Visual_scope));
							}
							else  //逃跑
							{
								this.Next_target.x = -this.x - (All_player[i].x + frogLineUser.x) / 2;
								this.Next_target.y = -this.y - (All_player[i].x + frogLineUser.x) / 2;
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
						}
					}
					//目标没连线(追击)
					else {
						if (this.otherLineUser == DataProl.account) {
							this.Next_target.x = (All_player[i].x - (this.x + AIUserMgr.getInstance().currentPlayer.x) / 2);
							this.Next_target.y = (All_player[i].y - (this.y + AIUserMgr.getInstance().currentPlayer.y) / 2);
							this.Next_target.normalize(this.Pursuit_weight * (1 - YouMe_distance / this.Visual_scope));
						}
						else {
							this.Next_target.x = (All_player[i].x - (this.x + serverAIMgr.getInstance().AIPools[this.otherLineUser].x) / 2);
							this.Next_target.y = (All_player[i].y - (this.y + serverAIMgr.getInstance().AIPools[this.otherLineUser].y) / 2);
							this.Next_target.normalize(this.Pursuit_weight * (1 - YouMe_distance / this.Visual_scope));
						}
					}
				}
				//自己没连线
				else {
					//目标连线
					if (All_player[i].ishadLine) {
						let closest_prop = this.GetClosestProps(this.Visual_scope);
						if (closest_prop != null) {
							let dis_m2p = MathUtils.getFootfallDistance(All_player[i].x, All_player[i].y, AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, this.x, this.y);
							let dis_m2o = MathUtils.getFootfallDistance(All_player[i].x, All_player[i].y, AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, closest_prop.x, closest_prop.y);
							let pt_m2o = MathUtils.getFootfallPoint(All_player[i].x, All_player[i].y, AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, closest_prop.x, closest_prop.y);
							if (dis_m2o > dis_m2p) {
								let target_pt = MathUtils.getOnePointOnLineAt(pt_m2o.x, pt_m2o.y, closest_prop.x, closest_prop.y, 2);
								this.Next_target.x = target_pt.x - this.x;
								this.Next_target.y = target_pt.y - this.y;
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
						}
						else if (All_player[i].otherLineUser == DataProl.account) {

							let dis_m2o = MathUtils.getFootfallDistance(All_player[i].x, All_player[i].y, AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, this.x, this.y);
							let pt_m2o = MathUtils.getFootfallPoint(All_player[i].x, All_player[i].y, AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, this.x, this.y);
							let on_line_m2o = MathUtils.checkPointOnSegment(All_player[i].x, All_player[i].y, AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, pt_m2o.x, pt_m2o.y);
							if (on_line_m2o) {
								this.Next_target.x = this.x - pt_m2o.x;
								this.Next_target.y = this.y - pt_m2o.y;
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
							else {
								this.Next_target.x = (this.x - (All_player[i].x + AIUserMgr.getInstance().currentPlayer.x) / 2);
								this.Next_target.y = (this.y - (All_player[i].y + AIUserMgr.getInstance().currentPlayer.y) / 2);
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
						}
						else {
							//	let dis_m2o = MathUtils.getFootfallDistance(frog.x, frog.y, serverAIMgr.getInstance().AIPools[frog.otherLineUser].x, serverAIMgr.getInstance().AIPools[frog.otherLineUser].y, this.x, this.y);
							let pt_m2o = MathUtils.getFootfallPoint(All_player[i].x, All_player[i].y, serverAIMgr.getInstance().AIPools[All_player[i].otherLineUser].x, serverAIMgr.getInstance().AIPools[All_player[i].otherLineUser].y, this.x, this.y);
							this.Next_target.x = this.x - pt_m2o.x;
							this.Next_target.y = this.y - pt_m2o.y;
							let on_line_m2o = MathUtils.checkPointOnSegment(All_player[i].x, All_player[i].y, serverAIMgr.getInstance().AIPools[All_player[i].otherLineUser].x, serverAIMgr.getInstance().AIPools[All_player[i].otherLineUser].y, pt_m2o.x, pt_m2o.y);
							if (on_line_m2o) {
								this.Next_target.x = this.x - pt_m2o.x;
								this.Next_target.y = this.y - pt_m2o.y;
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
							else {
								this.Next_target.x = (this.x - (All_player[i].x + AIUserMgr.getInstance().currentPlayer.x) / 2);
								this.Next_target.y = (this.y - (All_player[i].y + AIUserMgr.getInstance().currentPlayer.y) / 2);
								this.Next_target.normalize(this.Avoid_weight * (1 - YouMe_distance / this.Visual_scope));
							}
						}
					}
					//目标没连线
					else {
						//如果颜色一样朝对方方向移动
						if (this.frogType == All_player[i].frogType && this.enemyId != All_player[i].userId) {
							this.Next_target.x = -this.x + All_player[i].x;
							this.Next_target.y = -this.y + All_player[i].y;
							this.Next_target.normalize(this.Pursuit_weight * (1 - YouMe_distance / this.Visual_scope));
							if (YouMe_distance <= this.lineLength) {
								this.shoot();
							}
						}
					}
				}
				this.targetdir.offset(this.Next_target.x, this.Next_target.y);
			}
		}
		/**如果可视玩家为空 */
		if (Video_player.length == 0) {
			this.setRandomMoveDir();
		}
	}
	/**吐舌 */
	protected shoot() {
		if (!this.isCanShoot) {
			return;
		}
		let frog = webNetworkMananger.getInstance().gameSceneRec.m_createAllFrogs.findFrogById(this.userId);
		if (frog == null) {
			return;
		}
		frog.loll();
		this.isCanShoot = false;
		if (this.shootTimer == null)
			this.shootTimer = new egret.Timer(4000, 1);
		this.shootTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.restShoot, this);
		this.shootTimer.start();
	}
	/**重置吐舌 */
	protected restShoot() {
		this.shootTimer.stop();
		this.shootTimer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.restShoot, this);
		this.isCanShoot = true;
	}
	private setRandomMoveDirPoint = new egret.Point();
	/**随机移动 */
	protected setRandomMoveDir() {
		var moveDir = MathUtils.getRandomDir();
		//	moveDir = new egret.Point(moveDir.x, moveDir.y);
		this.setRandomMoveDirPoint.setTo(moveDir.x, moveDir.y);
		let randomLust = Math.random();
		this.setRandomMoveDirPoint.normalize(this.RandomMove_weight * randomLust);
		this.targetdir.offset(this.setRandomMoveDirPoint.x, this.setRandomMoveDirPoint.y);
	}
	/**是否撞边界 
	 * 撞到false
	*/
	protected checkPointValid(point): boolean {
		var isValid = true;
		if (point.x > 2450 || point.x < 50) {
			isValid = false;
		}

		if (point.y > 2440 || point.y < 65) {
			isValid = false;
		}
		return isValid;
	}
	private calculateTargetPointTmp = new egret.Point(0, 0);
	/**判断下次位置是否撞墙 */
	protected calculateTargetPoint() {
		var nextPoint = MathUtils.calculateNextPointEx(this.x, this.y, this.targetdir.x, this.targetdir.y, this.speed, false);
		if (!this.checkPointValid(nextPoint)) {
			this.calculateTargetPointTmp.setTo(-this.targetdir.x, -this.targetdir.y);
			this.calculateTargetPointTmp.normalize(this.Obstacle_weight);
			this.targetdir.offset(this.calculateTargetPointTmp.x, this.calculateTargetPointTmp.y);
		}

	}
	/**获取最近的玩家 */
	protected GetClosestUser() {


	}
	/**获取最近的道具 */
	protected GetClosestProps(disLimit: number) {
		let props = AIPropsMgr.getInstance().getRoomProps();
		let min_dis = 10000;
		let closest_prop;
		for (let j = 0; j < props.length; ++j) {
			let new_dis = MathUtils.distance(this.x, this.y, props[j].x, props[j].y);
			if (min_dis > new_dis) {
				min_dis = new_dis;
				closest_prop = props[j];
			}
		}
		if (min_dis > disLimit || closest_prop == undefined) {
			return null;
		}
		return closest_prop;
	}
	/**
	 * AI 思考 移动
	 */
	protected AIUpdate() {
		if (this.partner != null) {
			this.targetdir.setTo(0, 0);
			return;
		}
	
		//如果AI存在则更新AI中的时间戳
		if (this.isUsed && !this.death.isDeath && this.userId != DataProl.account) {//在使用，没死，不是玩家自己
			//获取时间
			var time = egret.getTimer();
			/**到达思考时间 */
			if (time - this.Think_time > this.Think_interval) {
				this.Think_interval = 500 + Math.floor(Math.random() * this.Think_interval);
				this.targetdir.setTo(0, 0);
				this.restChangeColorType();
				this.checkEnemy();
				this.Detect_line();
				this.checkIsBreakLine();
				this.DetectionProps();
				this.setRandomMoveDir();
				this.calculateTargetPoint();
				this.Detect_enemy();
				this.Think_time = time;
			}
		}
	}
	/**检测仇人 */
	public checkEnemy() {
		if (this.enemyId != null && !this.enemyTimer.running) {
			this.enemyTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.restEnemy, this);
			this.enemyTimer.start();
		}

	}
	/**重置仇人 */
	public restEnemy() {
		this.enemyTimer.stop();
		this.enemyTimer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.restEnemy, this);
		this.enemyId = null;
	}
	/**重置变色状态 */
	public restChangeColorType() {
		for (let i = 0; i < this.propStates.length; i++) {
			if (this.propStates[i].getPropType == 5) {
				if (this.changeColorTimer.running) {
					this.changeColorTimer.reset();
				} else {
					this.changeColorTimer.start();
				}
			}
		}
	}

	private haveSameTmpPoint = new egret.Point(0, 0);
	private haveSameTmp2Point = new egret.Point(0, 0);
	/**判断可视范围是否有同色青蛙 */
	protected haveSameFrogInMap() {
		/**房间内所有玩家 */
		let All_player = AIServer.getInstance().roomInfo.roomUser;
		/**自己的坐标 */
		this.haveSameTmpPoint.setTo(this.x, this.y);
		//	let My_position = new egret.Point(this.x, this.y);
		for (let i = 0; i < All_player.length; i++) {
			/**其他玩家坐标 */
			//	let Player_position = new egret.Point(All_player[i].x, All_player[i].y);
			this.haveSameTmp2Point.setTo(All_player[i].x, All_player[i].y);
			/**自己与其它玩家的距离 */
			let YouMe_distance = egret.Point.distance(this.haveSameTmpPoint, this.haveSameTmp2Point);
			//判断进入可视范围；不是自己；不是自己连线的玩家
			if (this.Visual_scope > YouMe_distance && All_player[i].userId != this.userId && this.otherLineUser != All_player[i].userId && All_player[i].frogType == this.frogType) {
				return true;
			}
		}
		return false;

	}
	private DetectionPropsP0tmp = new egret.Point(0, 0);
	private DetectionPropsP1tmp = new egret.Point(0, 0);
	private DetectionPropsP2tmp = new egret.Point(0, 0);
	private propDirection = new egret.Point(0, 0);
	/**探测道具 */
	public DetectionProps() {
		/**全部道具 */
		let props = AIPropsMgr.getInstance().getRoomProps();
		if (props == null) {
			return;
		}
		/**我的位置 */
		//	let myPoint = new egret.Point(this.x, this.y);
		this.DetectionPropsP0tmp.setTo(this.x, this.y);
		/**增益道具正方向
		     * 减益道具反方向
		    */
		//let propDirection: egret.Point;
		for (let i = 0; i < props.length; i++) {
			/**道具 */
			let prop = props[i];
			/**道具位置 */
			this.DetectionPropsP1tmp.setTo(prop.x, prop.y);
			//	let propPoint = new egret.Point(prop.x, prop.y);
			/**我和道具的距离 */
			let propDistance = egret.Point.distance(this.DetectionPropsP0tmp, this.DetectionPropsP1tmp);

			//进入可视范围
			if (propDistance <= this.Visual_scope) {
				//变色道具
				if (prop.type == 5) {
					if (this.haveSameFrogInMap() && !this.changeColorTimer.running) {
						this.propDirection.setTo(this.DetectionPropsP1tmp.x - this.DetectionPropsP0tmp.x, this.DetectionPropsP1tmp.y - this.DetectionPropsP0tmp.y);
						this.propDirection.normalize(this.prop_weight * (propDistance / this.Visual_scope));
						this.targetdir.offset(this.propDirection.x, this.propDirection.y);
						return;
					}
				}
				//躲避减益道具
				if (prop.type == 4 || prop.type == 2) {
					this.propDirection.setTo(this.DetectionPropsP0tmp.x - this.DetectionPropsP1tmp.x, this.DetectionPropsP0tmp.y - this.DetectionPropsP1tmp.y);
					//	propDirection = this.DetectionPropsP0tmp.subtract(this.DetectionPropsP1tmp);
					this.propDirection.normalize(this.prop_weight * (propDistance / this.Visual_scope));
					this.targetdir.offset(this.propDirection.x, this.propDirection.y);
					return;
				}
				//主动找荷叶道具
				if (prop.type == 6 || prop.type == 7) {
					this.propDirection.setTo(this.DetectionPropsP1tmp.x - this.DetectionPropsP0tmp.x, this.DetectionPropsP1tmp.y - this.DetectionPropsP0tmp.y);
					//	propDirection = this.DetectionPropsP1tmp.subtract(this.DetectionPropsP0tmp);
					this.propDirection.normalize(this.prop_weight * (propDistance / this.Visual_scope));
					this.targetdir.offset(this.propDirection.x, this.propDirection.y);
					return;
				}
			}
		}

	}

	private detectLinetmpPoint = new egret.Point(0, 0);
	private detectLinetmpPoint2 = new egret.Point(0, 0);
	private detectLinetmpPoint3 = new egret.Point(0, 0);
	/**探测断线 */
	protected Detect_line() {
		if (this.isError()) {
			return;
		}
		if (this.ishadLine) {
			/**所有玩家 */
			let All_player = serverAIMgr.getInstance().AIPools;
			/**自己下个点的坐标 */
			let MyNextPoint = MathUtils.calculateNextPointEx(this.x, this.y, this.targetdir.x, this.targetdir.y, this.speed, false);
			/**连线青蛙下个点的坐标 */
			let OtherNextPoint;
			/**最长线长 */
			let Max_line;
			if (this.otherLineUser == DataProl.account) {
				OtherNextPoint = MathUtils.calculateNextPointEx(AIUserMgr.getInstance().currentPlayer.x, AIUserMgr.getInstance().currentPlayer.y, AIUserMgr.getInstance().currentPlayer.targetdir.x, AIUserMgr.getInstance().currentPlayer.targetdir.y, AIUserMgr.getInstance().currentPlayer.speed, false);
				//Max_line = this.lineLength > AIUserMgr.getInstance().currentPlayer.lineLength ? this.lineLength : AIUserMgr.getInstance().currentPlayer.lineLength;
				Max_line = this.lineLength + AIUserMgr.getInstance().currentPlayer.lineLength;
			} else {
				OtherNextPoint = MathUtils.calculateNextPointEx(All_player[this.otherLineUser].x, All_player[this.otherLineUser].y, All_player[this.otherLineUser].targetdir.x, All_player[this.otherLineUser].targetdir.y, All_player[this.otherLineUser].speed, false);
				//Max_line = this.lineLength > All_player[this.otherLineUser].lineLength ? this.lineLength : All_player[this.otherLineUser].lineLength;
				Max_line = this.lineLength + All_player[this.otherLineUser].lineLength;
			}
			/**两只青蛙的距离 */
			let TwoForg_distance = MathUtils.distance(OtherNextPoint.x, OtherNextPoint.y, MyNextPoint.x, MyNextPoint.y);
			/**断线距离 */
			let Break_Line_distance = Max_line - TwoForg_distance;
			if (Break_Line_distance < (Max_line / 2)) {
				//	let offset_position = new egret.Point();
				this.detectLinetmpPoint.setTo(OtherNextPoint.x, OtherNextPoint.y);
				this.detectLinetmpPoint3.setTo(MyNextPoint.x, MyNextPoint.y);
				//offset_position = new egret.Point(MyNextPoint.x, MyNextPoint.y).subtract(new egret.Point(OtherNextPoint.x, OtherNextPoint.y));
				this.detectLinetmpPoint2.setTo(this.detectLinetmpPoint.x - this.detectLinetmpPoint3.x, this.detectLinetmpPoint.y - this.detectLinetmpPoint3.y);
				this.detectLinetmpPoint2.normalize(this.Line_weight * (1 - Break_Line_distance / Max_line));
				this.targetdir.offset(this.detectLinetmpPoint2.x, this.detectLinetmpPoint2.y);
			} else {
				this.detectLinetmpPoint.setTo(MyNextPoint.x, MyNextPoint.y);
				this.detectLinetmpPoint3.setTo(OtherNextPoint.x, OtherNextPoint.y);

				//offset_position = new egret.Point(MyNextPoint.x, MyNextPoint.y).subtract(new egret.Point(OtherNextPoint.x, OtherNextPoint.y));
				this.detectLinetmpPoint2.setTo(this.detectLinetmpPoint.x - this.detectLinetmpPoint3.x, this.detectLinetmpPoint.y - this.detectLinetmpPoint3.y);
				//	this.detectLinetmpPoint2 = this.detectLinetmpPoint.subtract(this.detectLinetmpPoint3);
				this.detectLinetmpPoint2.normalize(this.AddLine_weight * (1 - Break_Line_distance / Max_line));
				this.targetdir.offset(this.detectLinetmpPoint2.x, this.detectLinetmpPoint2.y);
			}
		} else {
			return;
		}
	}
}